package com.lagou.codec;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageCodec;
import io.netty.handler.codec.MessageToMessageDecoder;
import io.netty.util.CharsetUtil;

import java.util.List;

/**
 * @description: 消息解码器
 * @author: yx
 * @date: 2021/11/10 13:55
 */
public class MessageDecoder extends MessageToMessageDecoder {

    @Override
    protected void decode(ChannelHandlerContext ctx, Object msg, List out) throws Exception {
        System.out.println("正在进行消息解码...");
        ByteBuf byteBuf = (ByteBuf) msg;
        //传递给下一个处理器handler
        out.add(byteBuf.toString(CharsetUtil.UTF_8));
    }
}
